﻿var grid = null;
$(function () {
    $("#txtDate").ligerDateEditor({
        showTime: false,
        format: "yyyy-MM-dd",
        width: 90,
        cancelable: false
    });

    var isDeptAll = 1;
    $("#ddlDepartmentCode").ligerComboBox({
        cancelable: false,
        width: 100,
        url: "/Escort/EscortPersonnel/GetDepartmentList?isAll=" + isDeptAll + "&ram" + Math.random(),
        valueField: "value",
        textField: "text",
        valueFieldID: 'hdnDepartmentCode',
        value: $("#hdnJobTitle").val().indexOf("护理部") > -1 ? "-1" : $("#hdnCurrDepCode").val(),
        onSelected: function () {
            search();
        }
    });

    $('#btnSearch').click(function () {
        search();
    });

    $('#btnPrintSummary').click(function () {
        printSummary();
    });

    $('#btnSearch').click();
});

//搜索
function search(pageNumber) {
    var queryData = {
        date: $("#txtDate").val(),
        departmentCode: $("#hdnDepartmentCode").val()
    }
    initTable(queryData, pageNumber);
}

//加载列表
function initTable(queryData, pageNumber) {
    $("#maingrid").ligerGrid({
        height: '100%',
        url: '/Escort/EscortSummary/Search?ram=' + Math.random(),
        parms: queryData,
        page: pageNumber,
        pageSize: 30,
        rownumbers: true,
        heightDiff: 25,
        fixedCellHeight: false,
        allowHideColumn: false,
        usePager: false,
        columns: [
            { display: '日期', name: 'SEARCH_DATE', width: 100 },
            {
                display: '病区', columns:
                  [
                      { display: '说明', name: 'NURSE_CELL_NAME', width: 100 }
                  ]
            },
            {
                display: '在院病人', columns:
                  [
                      { display: '当前病人总数', name: 'ALL_PATIENT', width: 100 }
                  ]
            },
            {
                display: '陪护人员', columns:
                  [
                      {
                          display: '陪护总数', columns:
                            [
                                { display: '当日总人数', name: 'ALL_ESCORT', width: 100 },
                                { display: '当日有效人数', name: 'ALL_VALID', width: 100 },
                                { display: '当日停止人数', name: 'ALL_STOP', width: 100 }
                            ]
                      },
                      {
                          display: '泉州', columns:
                            [
                                { display: '籍贯为泉州市的陪护数', name: 'ALL_CITY', width: 140 }
                            ]
                      },
                      {
                          display: '省内外市', columns:
                            [
                                { display: '籍贯为福建省内泉州以外的城市陪护数', name: 'ALL_OTHER_CITY', width: 160 }
                            ]
                      },
                      {
                          display: '外省(注省份)', columns:
                            [
                                { display: '籍贯为福建外的城市陪护数', name: 'ALL_OTHER_PRO', width: 180 }
                            ]
                      },
                      {
                          display: '疫区(注区域)', columns:
                            [
                                { display: '勾选的区域', name: 'ALL_KEY_AREA', width: 140 }
                            ]
                      },
                      { display: '境外史', name: 'ALL_ABROAD', width: 100 }
                  ]
            },
            {
                display: '陪护超1人病人数', columns:
                  [
                      { display: '具体人数，备注具体病区、床号、姓名', name: 'ALL_OVER', width: 250 }
                  ]
            },
            {
                display: '陪护证更换', columns:
                  [
                      { display: '更换陪护的床号姓名', name: 'ALL_REPLACE', width: 140 }
                  ]
            }
            ,
            {
                display: '门诊病人进入', columns:
                  [
                      { display: '', name: '', width: 80 }
                  ]
            },
            {
                display: '说明', columns:
                  [
                      { display: '', name: '', width: 80 }
                  ]
            }
        ]
    });
    GridNoData($("#maingrid"));
}

Install_InsertReport();
var Installed = Install_Detect();
if (Installed) {
    CreateReport("Report");
    Report.LoadFromURL("/Grf/陪护数据汇总表.grf");
}

//设置导出参数
function OnExportBegin(OptionObject) {
    if (OptionObject.ExportType == 1) {
        var E2XLSOption = OptionObject.AsE2XLSOption;
        E2XLSOption.SameAsPrint = false;
        E2XLSOption.ExportPageBreak = false;
        E2XLSOption.ExportPageHeaderFooter = false;
        E2XLSOption.ColumnAsDetailGrid = false;
        E2XLSOption.OnlyExportDetailGrid = true;
    }
}

//导出汇总表
function printSummary() {
    try {
        var departmentCode = $("#hdnDepartmentCode").val();
        if (departmentCode == "-1") {
            departmentCode = $("#hdnDepartCode").val();
        }
        Report.OnExportBegin = OnExportBegin;
        Report.LoadDataFromURL("/Escort/EscortSummary/GetEscortSummaryPrint?date=" + $("#txtDate").val() + "&departmentCode=" + departmentCode);
        Report.ExportDirect(1, "陪护数据汇总表.xls", true, true);
    }
    catch (e) {
        $('html,body').animate({ scrollTop: $(document).height() }, 1000);
    }
}